﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lottery.MediaData.UI.Control {
    /// <summary>
    /// 选择场次
    /// </summary>
    public partial class SelectNice : UserControl {
        public SelectNice() {
            InitializeComponent();

            labelInfo.Text = string.Empty;

            m_controls.Add(checkBox1);
            m_controls.Add(checkBox2);
            m_controls.Add(checkBox3);
            m_controls.Add(checkBox4);
            m_controls.Add(checkBox5);
            m_controls.Add(checkBox6);
            m_controls.Add(checkBox7);
            m_controls.Add(checkBox8);
            m_controls.Add(checkBox9);
            m_controls.Add(checkBox10);
            m_controls.Add(checkBox11);
            m_controls.Add(checkBox12);
            m_controls.Add(checkBox13);
            m_controls.Add(checkBox14);
        }

        private List<CheckBox> m_controls = new List<CheckBox>();

        public bool IsOK {
            get {
                int count = 0;
                foreach (var item in m_controls) {
                    if (item.Checked) count++;
                }
                return count == MaxCount;
            }
        }

        /// <summary>
        /// 场次
        /// </summary>
        public string CC {
            get {
                var sb = new StringBuilder();
                bool isFirst = true;
                for (int i = 0; i < m_controls.Count; i++) {
                    if (m_controls[i].Checked) {
                        if (!isFirst) sb.Append("-");

                        sb.Append(i + 1);
                        if (isFirst) isFirst = false;
                    }
                }
                return sb.ToString();
            }
        }

        public int MaxCount { get; set; }

        private void checkBox1_Click(object sender, EventArgs e) {
            int count = 0;
            foreach (var item in m_controls) {
                if (item.Checked) count++;
            }

            if (count == MaxCount)
                labelInfo.ForeColor = System.Drawing.Color.Black;
            else
                labelInfo.ForeColor = System.Drawing.Color.Red;

            labelInfo.Text = string.Format("已选择 {0}场(总计 {1}场)", count, MaxCount);
        }
    }
}
